package cn.ryh.jdbctemplate.dao;

import cn.ryh.jdbctemplate.entity.User;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;


/**
 * @ClassName JdbcTemplateDao
 * @Description 测试JdbcTemplate的dao
 * @Author RaoYH
 */
@Repository
public class JdbcTemplateDao {
    @Resource
    private JdbcTemplate jdbcTemplate;

    public User getUser(Integer id){
        String sql = "SELECT * FROM USER WHERE id = ?";
        RowMapper<User> rowMapper = new BeanPropertyRowMapper<>(User.class);
        return jdbcTemplate.queryForObject(sql, rowMapper,id);
    }
}
